new Vue({
  el: '#main',
  data: {
    unfold: null,
    queryGroup: {
      majorName: '',
      educationalLevel: [],
      fuzzy: false,
    },
    list: null,
    pagination: null,
  },
  computed: {
    unfoldOrfold() {
      return this.unfold ? '收起' : '展开'
    },
  },
  methods: {
    getInitStatus() {
      this.unfold = this.$refs.collapse.classList.contains('show')
    },
    toggle() {
      this.unfold = !this.unfold
    },
    query(targetPage) {
      // 预留查询方法
      let data = {
        type: 'query',
        queryGroup: this.queryGroup,
      }
      if (this.pagination && targetPage && typeof targetPage != "object") data.pageNum = targetPage
      $.ajax({
        url: '/levelMajorInfo',
        type: 'POST',
        data: JSON.stringify(data),
        contentType: 'application/json;charset=utf-8',
        dataType: 'json',
        success: (data) => {
          // console.log(data)
          if (data.status) {
            // 获取分页信息
            this.$set(this, 'pagination', data.pagination)
            // 获取列表信息
            this.$set(this, 'list', data.pagination.list)
          }else {
            this.$set(this, 'pagination', null)
            this.$set(this, 'list', null)
          }
          this.alert(data.msg, data.status ? 'success' : 'danger', 1500)
        },
        error: (XMLHttpRequest, textStatus, errorThrown) => {
          this.alert('系统错误：' + errorThrown, 'danger', 1500)
        },
      })
    },
    exportInfo() {
      // 预留导出方法
      let data = {
        type: 'export',
      }
      $.ajax({
        url: '#!',
        type: 'POST',
        data: JSON.stringify(data),
        contentType: 'application/json;charset=utf-8',
        dataType: 'json',
        success: (data) => {
          this.alert(data.msg, data.status ? 'success' : 'danger', 1500)
        },
        error: (XMLHttpRequest, textStatus, errorThrown) => {
          // console.log('状态码：', XMLHttpRequest.status)
          // console.log('状态：', XMLHttpRequest.readyState)
          // console.log('错误信息：', errorThrown)
          this.alert('系统错误：' + errorThrown, 'danger', 1500)
        },
      })
    },
    importInfo() {
      // 预留导入方法
    },
    add() {
      // 预留添加方法
    },
    alert(msg, type, delay) {
      // 三个参数依次为提示信息（string），提示类型（string），delay（滞留时间，ms为单位）
      $.notify(
        {
          message: msg,
        },
        {
          type: type,
          placement: {
            from: 'top',
            align: 'center',
          },
          z_index: 10800,
          delay: delay,
          animate: {
            enter: 'animate__animated animate__shakeX',
            exit: 'animate__animated animate__fadeOutDown',
          },
        }
      )
    },
  },
  watch: {
    // queryGroup: {
    //   handler(nd) {
    //     console.log(nd.educationalLevel)
    //   },
    //   deep: true,
    // },
  },
  created() {
    this.query()
  },
  mounted() {
    this.getInitStatus()
  },
})
